package stringUtil.charsetTest;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;

public class MoneyChinsesUpper {
	public static void main(String[] args) {
		System.out.println(ChineseCurrency(123000080.123));
	}
	
	public static String ChineseCurrency(double num){
		String s = new DecimalFormat("#.00").format(num);
		System.out.println(s);
		char[] digit = { '零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖' };
		String unit = "仟佰拾兆仟佰拾亿仟佰拾万仟佰拾元角分";
		String str=s.replaceAll("\\.", "");
//		System.out.println(str);
		//char[] strs=str.toCharArray();
		int l = unit.length();
		StringBuffer sb=new StringBuffer(unit.substring(l-str.length(), l));
		System.out.println(sb.toString());
		for (int i = str.length()-1; i >=0 ; i--) {
			System.out.println(str.charAt(i));
			sb = sb.insert(i, digit[(str.charAt(i)- 0x30)]);
		}
		System.out.println(sb.toString());
		s=sb.toString();
		//表示替换零拾、零佰、零仟的字段        //连续两个或以上的                    //匹配零兆、零万、零元的字符替换成对应的值
		s = s.replaceAll("零[拾佰仟]", "零").replaceAll("零{2,}", "零").replaceAll("零([兆万元])", "$1").replaceAll("零[角分]", "");
		if (s.endsWith("角"))
			s += "零分";
		if (!s.contains("角") && !s.contains("分") && s.contains("元"))
			s += "整";
		if (s.contains("分") && !s.contains("整") && !s.contains("角"))
			s = s.replace("元", "元零");
		return s;
	}
	
	/*壹亿贰仟叁佰零万零捌拾玖元壹角贰分
	 * public static String ChineseCurrency(double num){
		char[] str={'零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'};
		String unit = "仟佰拾兆仟佰拾亿仟佰拾万仟佰拾元角分";
	//	BigDecimal bg = new BigDecimal(num).setScale(2, RoundingMode.UP);//四舍五入
	//	double n= bg.doubleValue();
		String[] numStr=String.valueOf(num).split("\\.");
		if(numStr.length==2){
			
		}
		char[] nums = String.valueOf(numStr).toCharArray(); //将数字转换成数组
		StringBuilder strBu=new StringBuilder("");
		for (int i = nums.length; i > 0; i--) {
			strBu.append(str[Integer.parseInt(nums[i] + "")]);
//			System.out.println(nums[i]);
		}
		System.out.println(strBu);
		return null;
	}*/
	
}
